package com.ambercrm.business;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ambercrm.R;
import com.ambercrm.base.BaseTitleActivity;
import com.ambercrm.business.bean.AuthBean;
import com.ambercrm.business.bean.LoginUserInfo;
import com.ambercrm.tools.EmptyUtils;

import java.io.Serializable;

public class UserInfoActivity extends BaseTitleActivity {

    private LoginUserInfo userInfo;
    private RelativeLayout rlDisplayInfo;
    private TextView tvDisplayName;
    private ImageView ivUserIcon;
    private TextView tvDepartName;
    private TextView tvEmployeeName;
    private TextView tvWorkNumber;
    private TextView tvEmail;


    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_user_info;
    }

    @Override
    protected void initContentView(View v) {
        mTitleText.setText("个人资料");
        Bundle bundle = getBundle();
        if (bundle != null) {
            userInfo = (LoginUserInfo) bundle.getSerializable("userInfo");
        }
        ivUserIcon = findViewById(R.id.iv_user_icon);
        rlDisplayInfo = findViewById(R.id.rl_display_info);
        tvDisplayName = findViewById(R.id.tv_display_name);
        tvDepartName = findViewById(R.id.tv_depart_name);
        tvEmployeeName = findViewById(R.id.tv_employee_name);
        tvWorkNumber = findViewById(R.id.tv_work_number);
        tvEmail = findViewById(R.id.tv_email);
        initData();
    }

    private void initData() {
        if (userInfo != null) {
            AuthBean auth = userInfo.getAuth();
            if (EmptyUtils.notEmpty(auth.getDisplay())) {
                ivUserIcon.setVisibility(View.GONE);
                rlDisplayInfo.setVisibility(View.VISIBLE);
                tvDisplayName.setText(auth.getDisplay());
            }

            if (EmptyUtils.notEmpty(auth.getManageDepartNames())) {
                tvDepartName.setText(auth.getManageDepartNames());
            }
            if (EmptyUtils.notEmpty(auth.getEmployeePositionName())) {
                tvEmployeeName.setText(auth.getEmployeePositionName());
            }
            if (EmptyUtils.notEmpty(auth.getCode())) {
                tvWorkNumber.setText(auth.getCode());
            }
            if (EmptyUtils.notEmpty(auth.getEmail())) {
                tvEmail.setText(auth.getEmail());
            }
        }
    }
}
